Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | "use client"; import { useParams } from "next/navigation"; import { useMemo, useState } from "react"; import Link from "next/link"; import { apiRegistry } from "@/lib/api-docs/registry"; import { getMethodColor } from "@/lib/api-docs/executor"; import { ApiTester } from "@/components/features/admin/api-docs"; import { ApiEndpoint } from "@/types/api-docs"; export default function CategoryPage() { const params = useParams(); const categoryId = params.category as string; const [selectedEndpoint, setSelectedEndpoint] = useState<ApiEndpoint | null>(null); const [searchQuery, setSearchQuery] = useState(""); const category = useMemo(() => { return apiRegistry.categories.find((c) => c.id === categoryId); }, [categoryId]); const filteredEndpoints = useMemo(() => { if (!category) return []; if (!searchQuery.trim()) return category.endpoints; const query = searchQuery.toLowerCase(); return category.endpoints.filter( (endpoint) => endpoint.summary.toLowerCase().includes(query) || endpoint.path.toLowerCase().includes(query) || endpoint.description?.toLowerCase().includes(query) ); }, [category, searchQuery]); if (!category) { return ( <div className="min-h-screen bg-gray-50 dark:bg-gray-900 p-8"> <div className="max-w-4xl mx-auto text-center"> <h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4"> Category Not Found </h1> <p className="text-gray-600 dark:text-gray-400 mb-6"> The category "{categoryId}" does not exist. </p> <Link href="/admin/api-docs" className="text-blue-600 hover:text-blue-800 dark:text-blue-400" > ← Back to API Documentation </Link> </div> </div> ); } return ( <div className="min-h-screen bg-gray-50 dark:bg-gray-900"> {/* Header */} <div className="bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700"> <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6"> <div className="flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 mb-4"> <Link href="/admin/api-docs" className="hover:text-blue-600"> API Documentation </Link> <span>/</span> <span className="text-gray-900 dark:text-white">{category.name}</span> </div> <h1 className="text-3xl font-bold text-gray-900 dark:text-white"> {category.name} </h1> <p className="mt-2 text-gray-600 dark:text-gray-400"> {category.description} </p> <div className="mt-4 flex items-center gap-4"> <span className="text-sm text-gray-500 dark:text-gray-400"> {category.endpoints.length} endpoint{category.endpoints.length !== 1 ? "s" : ""} </span> </div> </div> </div> <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8"> <div className="grid grid-cols-1 lg:grid-cols-2 gap-8"> {/* Endpoints List */} <div> <div className="mb-6"> <input type="text" placeholder="Search endpoints..." value={searchQuery} onChange={(e) => setSearchQuery(e.target.value)} className="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent" /> </div> <div className="space-y-3"> {filteredEndpoints.map((endpoint) => ( <button key={endpoint.id} onClick={() => setSelectedEndpoint(endpoint)} className={`w-full text-left p-4 rounded-lg border transition-all ${ selectedEndpoint?.id === endpoint.id ? "border-blue-500 bg-blue-50 dark:bg-blue-900/20" : "border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:border-gray-300 dark:hover:border-gray-600" }`} > <div className="flex items-center gap-3 mb-2"> <span className={`px-2 py-0.5 text-xs font-medium rounded ${getMethodColor( endpoint.method )}`} > {endpoint.method} </span> <code className="text-sm text-gray-700 dark:text-gray-300 font-mono"> {endpoint.path} </code> </div> <p className="text-sm font-medium text-gray-900 dark:text-white"> {endpoint.summary} </p> {endpoint.description && ( <p className="mt-1 text-xs text-gray-500 dark:text-gray-400 line-clamp-2"> {endpoint.description} </p> )} <div className="mt-2 flex items-center gap-2"> {endpoint.requiresAuth && ( <span className="px-2 py-0.5 text-xs bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 rounded"> Auth Required </span> )} {endpoint.adminOnly && ( <span className="px-2 py-0.5 text-xs bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 rounded"> Admin Only </span> )} </div> </button> ))} {filteredEndpoints.length === 0 && ( <div className="text-center py-8 text-gray-500 dark:text-gray-400"> No endpoints found matching "{searchQuery}" </div> )} </div> </div> {/* Endpoint Detail / Tester */} <div className="lg:sticky lg:top-8 lg:self-start"> {selectedEndpoint ? ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden"> <div className="p-4 border-b border-gray-200 dark:border-gray-700"> <div className="flex items-center justify-between"> <h2 className="text-lg font-semibold text-gray-900 dark:text-white"> {selectedEndpoint.summary} </h2> <Link href={`/admin/api-docs/${categoryId}/${selectedEndpoint.id}`} className="text-sm text-blue-600 hover:text-blue-800 dark:text-blue-400" > Full Details → </Link> </div> </div> <div className="p-4"> <ApiTester endpoint={selectedEndpoint} /> </div> </div> ) : ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center"> <div className="text-gray-400 dark:text-gray-500 mb-4"> <svg className="w-16 h-16 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24" > <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" /> </svg> </div> <h3 className="text-lg font-medium text-gray-900 dark:text-white mb-2"> Select an Endpoint </h3> <p className="text-sm text-gray-500 dark:text-gray-400"> Click on an endpoint from the list to view details and test it </p> </div> )} </div> </div> </div> </div> ); } |